// pages/login/login.js
let {login} = require('../../api/userApi')
Page({
  data:{
    userName : '',
    password : '',
  },
  goReg() {
    wx.navigateTo({
      url: '/pages/reg/reg',
    })
  },
  inputUser(ev) {
    let {value} = ev.detail;
    this.setData({userName:value});
  },
  inputPsw(ev) {
    let {value} = ev.detail;
    this.setData({password:value});
  },
  loginBtn(){
    let {password,userName} = this.data;
    if(password && userName){
      login(userName,password).then(res => {
        console.log('登陆结果',res.data);
        if(res.data.code){
          let userInfo = {userName,token:res.data.token,uid:res.data.uid};
          wx.setStorageSync('userInfo', userInfo);
          wx.reLaunch({
            url: '/pages/my/my',
          })
        }
      })
    }else{
      wx.showModal({
        title: '警告',
        content: '请填写完整的数据',
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  }
})